<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:f="http://java.sun.com/jsf/core">
	<f:view>
	<ui:composition template="/template/templatePadrao.xhtml">
		
		<ui:define name="body">
		
		<h:form id="form">
			<p:growl id="growl" />
				<h:outputText value="Fluxo de Caixa" styleClass="breadcrumb"/>
				<p:dataTable value="#{fluxoCaixaManager.contas}" 
					var="conta" style="width:100%" emptyMessage="Não existem Dados.">
					
					<f:facet name="header">
						<ui:include src="/financeiro/paginas/fluxoCaixa/tableHeader.xhtml" />
					</f:facet>
					
					<p:column headerText="Data" style="width: 10%; text-align:left;">
						<h:outputText value="#{conta.dataRealPagamento}" > 
							<f:convertDateTime pattern="dd/MM/yyyy" />
						</h:outputText>
					</p:column>
					<p:column headerText="Descrição" style="width: 50%; text-align:left;">
						<h:panelGroup rendered="#{conta.class.name.equals('br.com.sgc.entities.financeiro.ContasReceber')}">
							<h:outputText value="Venda de Produtos: Cliente #{conta.pedidoVenda.cliente.pessoa.displayNome}" />
						</h:panelGroup>
						<h:panelGroup rendered="#{conta.class.name.equals('br.com.sgc.entities.financeiro.ContasPagar')}">
							<h:outputText value="Compra de Produtos: Fornecedor #{conta.pedidoCompra.fornecedor.razaoSocial}" />
						</h:panelGroup>
					</p:column>
					<p:column headerText="Entrada" style="width: 20%; text-align: right;">
						<h:panelGroup rendered="#{conta.class.name.equals('br.com.sgc.entities.financeiro.ContasReceber')}">
							<h:outputText value="R$ " />
							<h:outputText value="#{conta.valorPagamento}">
								<f:convertNumber pattern="#,##0.00;(#,##0.00)" />
							</h:outputText>
						</h:panelGroup>
					</p:column>
					<p:column headerText="Saída" style="width: 20%; text-align: right;">
						<h:panelGroup style="color:red;" rendered="#{conta.class.name.equals('br.com.sgc.entities.financeiro.ContasPagar')}">
							<h:outputText value="R$ " />
							<h:outputText value="#{conta.valorPagamento}">
								<f:convertNumber pattern="#,##0.00;(#,##0.00)" />
							</h:outputText>
						</h:panelGroup>
					</p:column>
					<f:facet name="footer">
						<ui:include src="/financeiro/paginas/fluxoCaixa/tableFooter.xhtml" />
					</f:facet>
				</p:dataTable>
			</h:form>
			
			<p:dialog widgetVar="dlg_caixa" modal="true" resizable="false" height="160" closable="false" closeOnEscape="true">
				<h:form id="form_caixa">
					<center><h:outputText value="Deseja Fechar o Caixa?" style="font-size: 25px;"/></center>
					<hr />	
					<table>
						<tr>
							<td>
								<h:outputText value="Data do Caixa" />
							</td>
							<td>
								<h:outputText value="#{fluxoCaixaManager.caixa.dataCaixa}">
									<f:convertDateTime pattern="dd/MM/yyyy" />
								</h:outputText>
							</td>
						</tr>
						<tr>
							<td>
								<h:outputText value="Saldo Anterior" />
							</td>
							<td>
								<h:outputText value="#{fluxoCaixaManager.caixa.saldoAnterior}">
									<f:convertNumber pattern="#,##0.00;(#,##0.00)" />
								</h:outputText>
							</td>
						</tr>
						<tr>
							<td>
								<h:outputText value="Saldo Atual" />
							</td>
							<td>
								<h:outputText value="#{fluxoCaixaManager.caixa.saldoAtual}">
									<f:convertNumber pattern="#,##0.00;(#,##0.00)" />
								</h:outputText>
							</td>
						</tr>
						
					</table>
					<hr />	
					<center>
						<p:commandButton value="Sim" action="#{fluxoCaixaManager.save}" oncomplete="dlg_caixa.hide();" update=":form" icon="ui-icon-check" rendered="#{fluxoCaixaManager.caixa.id == null}"/>
						<p:commandButton value="Sim" action="#{fluxoCaixaManager.update}" oncomplete="dlg_caixa.hide();" update=":form" icon="ui-icon-check" rendered="#{fluxoCaixaManager.caixa.id != null}"/>
						<p:commandButton value="Não" onclick="dlg_caixa.hide();" icon="ui-icon-close"/>
					</center>
				</h:form>
			</p:dialog>
			
			<p:dialog widgetVar="dlg_reabrir_caixa" modal="true" resizable="false" closable="false" closeOnEscape="true">
				<h:form id="form_reabrir_caixa">
					<center><h:outputText value="Deseja Reabrir o Caixa?" style="font-size:25px;"/></center>
					<hr />
					<center>
						<p:commandButton action="#{fluxoCaixaManager.reabrirCaixa}" value="Sim" oncomplete="dlg_reabrir_caixa.hide();" update=":form" icon="ui-icon-check"/>
						<p:commandButton onclick="dlg_reabrir_caixa.hide();" value="Não" icon="ui-icon-close"/>
					</center>
				</h:form>
			</p:dialog>
		</ui:define>
	</ui:composition>
	</f:view>
</html>